package concurrent;

import sun.misc.Unsafe;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @program: study2025
 * @description: ArrayList线程不安全测试
 * @author: liuChangFu
 * @data: 2025-02-10 17:25
 **/
public class ListTest {

    private static final Unsafe unsafe = Unsafe.getUnsafe();

    public static void main(String[] args) {
         List<Integer> list1 = new ArrayList<>();
        List<Integer> list = Collections.synchronizedList(list1);
        for (int i = 0; i < 5000; i++) {
            int finalI = i;
            new Thread(()->list.add(finalI)).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(list.size());
    }
}
